/*
 * Static.h
 *
 *  Created on: 2013. 12. 3.
 *      Author: jjaehuny
 */

#ifndef PROJECTZ_NGAMELOG_STATIC_H_
#define PROJECTZ_NGAMELOG_STATIC_H_

#include "MySql.h"
#include "MongoDB.h"
#include "Bson.h"

#include "../NUtil/Single.h"
#include "../NUtil/Pool.h"

namespace ProjectZ { namespace NGameLog {

class Static : public NUtil::Single<Static>
{
public:
	typedef NUtil::Pool<Bson> BSONPOOL;

public:
	Static()
	{
		_pMySql		= new MySql;
		_pMongoDB	= new MongoDB(1);

		_clsBsonPool = new BSONPOOL(1024);
	}

	~Static()
	{
		delete _pMongoDB;
		delete _pMySql;

		delete _clsBsonPool;
	}

	Bson * NEW()
	{
		Bson * pBson;
		std::lock_guard<std::mutex> lock(_mutex);
		{
			pBson = _clsBsonPool->NEW();
		}

		return pBson;
	}

	void DEL(Bson * pBson)
	{
		std::lock_guard<std::mutex> lock(_mutex);
		{
			_clsBsonPool->DEL(pBson);
		}
	}

public:
	MySql	*	GetMySql() { return _pMySql; }
	MongoDB *	GetMongoDB() { return _pMongoDB; }

	BSONPOOL * GETBSONPOOL() { return _clsBsonPool; }


private:
	MySql	*	_pMySql;
	MongoDB	* 	_pMongoDB;

	BSONPOOL *	_clsBsonPool;

	std::mutex _mutex;
};

} /*NGameLog*/ } /*ProjectZ*/

#endif /* PROJECTZ_NGAMELOG_STATIC_H_ */
